/**
 * 金叉形态，dif上穿dea。一般上穿当日会有较大的涨幅突破，紧跟着会有回调，通过查看4天以前的金叉，结合回调是否到位作为买入参考
 */
create or replace function getstjc(days int) returns setof record as
$$
declare
rec record;
begin
  for rec in EXECUTE '
	select b."date",b.code,b.macd, --b.zf,
		s."name",s.industry from basic_data b  left join stocks s  on b.code=s.code 
	where 
	to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days||')
	--and macd::float8 >0
    and strpos(s."name",''ST'')=0
	and dif > 0
	and s.outstanding*b."close">100
	and dif >=dea 
	and 0 > (select dif-dea from basic_data where to_date(date,''YYYY-MM-DD'') = getwd(current_date,'||days+1||') and code=b.code )
	 ;
	 ' loop
    return next rec;
  end loop;
return;
end
$$
language 'plpgsql';